getElementById
<div id="foo">...</div>という要素を取得したい場合は、document.getElementById('foo')と実行することでその要素を取得できます。もし、存在しない場合はnullになります。
querySelector と querySelectorAll
CSS のセレクタで要素を取得できます。querySelectorは対象の要素かnullが、querySelectorAllは対象の要素の配列(無ければ空配列)を返します。
document.querySelector('.foo');
document.querySelectorAll('.foo, [data-testid="bar"]');